class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

f = A("f")
e = B("e")
c = A("c")
n = B("n")
g = B("g")
a = B("a")
l = A("l")
j = A("j")
h = A("h")
k = B("k")

f.y = l
e.r = l
c.y = l
n.r = h
g.r = j
a.r = l
l.y = f
j.y = f
h.y = c
k.r = j
assert n.r.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

f = A("f")
e = B("e")
c = A("c")
n = B("n")
g = B("g")
a = B("a")
l = A("l")
j = A("j")
h = A("h")
k = B("k")

f.y = l
e.r = l
c.y = l
n.r = h
g.r = j
a.r = l
l.y = f
j.y = f
h.y = c
k.r = j
assert n.r.y.y.y.y.txt == "l"