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

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

k = A("k")
f = B("f")
d = A("d")
a = B("a")
b = A("b")
h = A("h")
j = B("j")
e = A("e")

k.x = d
k.r = f
f.r = a
f.t = d
d.x = h
d.r = j
a.r = j
a.t = d
b.x = h
b.r = f
h.x = d
h.r = f
j.r = f
j.t = h
e.x = k
e.r = a
assert j.t.r.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.r: B = None
        self.txt = txt

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

k = A("k")
f = B("f")
d = A("d")
a = B("a")
b = A("b")
h = A("h")
j = B("j")
e = A("e")

k.x = d
k.r = f
f.r = a
f.t = d
d.x = h
d.r = j
a.r = j
a.t = d
b.x = h
b.r = f
h.x = d
h.r = f
j.r = f
j.t = h
e.x = k
e.r = a
assert j.t.r.t.r.txt == "j"