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

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

e = A("e")
d = B("d")
j = A("j")
a = B("a")
h = A("h")

e.r = j
e.t = j
d.o = a
d.s = e
j.r = h
j.t = h
a.o = d
a.s = e
h.r = j
h.t = e
assert e.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.t: A = None
        self.txt = txt

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

e = A("e")
d = B("d")
j = A("j")
a = B("a")
h = A("h")

e.r = j
e.t = j
d.o = a
d.s = e
j.r = h
j.t = h
a.o = d
a.s = e
h.r = j
h.t = e
assert e.r.r.r.txt == "j"